package org.redmagic.agent.location.file;

import java.net.URI;
import java.util.Properties;
import java.util.Set;

import org.redmagic.location.UriLocation;
import org.redmagic.utils.Conditions;
import org.redmagic.utils.Properties2;

public class FileLocation extends UriLocation {

    public FileLocation(String uri) {
        super(uri);
    }

    public FileLocation(URI uri) {
        super(uri);
    }

    @Override
    public Properties resolvePlaceholders(Set<String> unresolvedPlaceholders) {
        Conditions.notNull(unresolvedPlaceholders, "unresolvedPlaceholders");
        Properties propertiesFromFile = Properties2.load(getURI());
        Properties resolvedProperties = new Properties();
        for (String placeHolder : unresolvedPlaceholders) {
            String value = propertiesFromFile.getProperty(placeHolder);
            if (value != null) {
                resolvedProperties.put(placeHolder, value);
            }
        }
        return resolvedProperties;
    }
}